/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asset;

import com.jme3.animation.AnimControl;
import com.jme3.animation.Skeleton;
import com.jme3.animation.SkeletonControl;
import com.jme3.material.Material;
import com.jme3.scene.Node;

/**
 *
 * @author
 */
public class Rig {

    Skel skel;
    MeshSet meshSet;

    public Rig(Skel skel, MeshSet meshSet) {
        this.skel = skel;
        this.meshSet = meshSet;
    }

    public MeshSet getMeshSet() {
        return meshSet;
    }

    public Skel getSkel() {
        return skel;
    }

    public Node instantiate(String nodeName, Material mat) {
        
        // Instantiate mesh data
        Node modelNode = meshSet.instantiate(nodeName, mat);

        // Clone the skeleton for animation purposes. This copies the
        // bind pose of the skeleton (so do not call setBindingPose() on 
        // the clone, because then the binding pose for all bones becomes
        // the identity).
        Skeleton s = new Skeleton(skel.getSkeleton());        

        // Create skeleton control
        SkeletonControl skeletonControl = new SkeletonControl(s);
        modelNode.addControl(skeletonControl);        
        
        // Create animation control
        AnimControl animControl = new AnimControl(s);
        modelNode.addControl(animControl);
        
        return modelNode;
    }
}
